package edu.java.lectures.lec14.collections.usage;

import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;

public class MapTest {

    private static final String LINE = "-----------------------";

    public static void main(String[] args) {
	System.out.println(LINE);
	Map<String, Integer> str2intMap = new HashMap<String, Integer>();

	String penchoKey = "pencho";
	str2intMap.put(penchoKey, new Integer(22));
	str2intMap.put("mincho", 32);
	str2intMap.put("tsetso", 100);

	System.out.println(str2intMap);

	System.out.println(str2intMap.get(penchoKey));

	System.out.println(str2intMap.get("koko"));

	System.out.println(str2intMap.put(penchoKey, 23));
	System.out.println(str2intMap);

	str2intMap.put(null, 3);
	System.out.println(str2intMap);
	System.out.println(str2intMap.get(null));

	System.out.println(LINE);
	for (Entry<String, Integer> str2IntEntry : str2intMap.entrySet()) {
	    System.out.println(str2IntEntry);
	}

	System.out.println(LINE);
	for (String strKey : str2intMap.keySet()) {
	    System.out.println(str2intMap.get(strKey));
	}

	System.out.println(LINE);
	for (Integer intValue : str2intMap.values()) {
	    System.out.println(intValue);
	}

	str2intMap.keySet().iterator();
	str2intMap.values().iterator();

	System.out.println(LINE);
	str2intMap.remove(null);
	System.out.println(str2intMap);
	

	// ------------ Ordered map -----------
	Map<String, Integer> str2IntOrderedMap = new LinkedHashMap<String, Integer>();

	str2IntOrderedMap.put(penchoKey + "2", new Integer(22));
	str2IntOrderedMap.put("mincho2", 32);
	str2IntOrderedMap.put("tsetso2", 100);

	System.out.println(str2IntOrderedMap);

	System.out.println(LINE);
	Iterator keysIter = str2IntOrderedMap.keySet().iterator();
	while (keysIter.hasNext()) {
	    System.out.println(keysIter.next());
	}

	System.out.println(LINE);
	Set<String> setKeysString = str2IntOrderedMap.keySet();
	for (String key : setKeysString) {
	    System.out.println(key);
	}

    }
}
